#pragma once 
#include <Arduino.h>
#include "Modbus_RTU.h"
#define DepthSensorBaudRate 9600 //设备波特率
class DepthSensor
{
public:
    enum FuncCode{ReadFuncCode = 0x03, //读取功能码
                    SetFuncCOde = 0x06, //写入功能码
                    DevNumAddr = 0x0000,  //设备编号数据地址-读写
                    DevBaudRateAddr = 0x0001, //设备波特率数据地址-读写
                    ReadPressureUnitAddr = 0x0002,//设备压力单位数据地址-读
                    ReadNumberOfPointAddr = 0x0003,  //小数点位置数据地址-读
                    ReadMeasurementsAddr = 0x0004,  //深度数据地址-读
                    ReadMinValueAddr = 0x0005,  //最小量程-读
                    ReadMaxValueAddr = 0x0006  //最大量程-读
                    };
    enum _BaudRate {
        BaudRate_1200 = 0x0000,  //波特率-写入用
        BaudRate_2400 = 0x0001,
        BaudRate_4800 = 0x0002,
        BaudRate_9600 = 0x0003,
        BaudRate_19200 = 0x0004,
        BaudRate_38400 = 0x0005,
        BaudRate_57600 = 0x0006,
        BaudRate_115200 = 0x0007
    };
    void initFunc(Modbus_RTU * _modbus);
    int ReadDepth(void);
    void SetBauteRate(DepthSensor::_BaudRate baudRate);// 设置波特率后，初始化要改波特率，并重新烧录程序
    void SetDevNum(unsigned short DevId); // 设置完设备id后，要改程序，并重新烧录
private:
    Modbus_RTU * modbus;
    uint16_t CRC_for_ReadDepth;
    void SetFunc(DepthSensor::FuncCode func, short SetData);
    short ReadFun(DepthSensor::FuncCode func);
    void SendData(unsigned char * pdata, int num);
    bool RecvData(unsigned char * poutData, int num);
};
